package com.iven.xie.designpattern.adapter.sms;

/**
 * 结合策略模式、工厂模式、适配器模式
 *
 * @author iven.xie
 */
public class SmsAdapter implements ISmsAdapter {

    @Override
    public String aliSmsSend(String mobile, String context) {
        return processSms(mobile, context, AliDaYuSmsAdapter.class);
    }

    @Override
    public String daHanSanTongSmsSend(String mobile, String context) {
        return processSms(mobile, context, DaHanSanTongSmsAdapter.class);
    }

    public String processSms(String mobile, String context, Class<? extends SmsChannel> clazz) {
        String result = null;
        try {
            SmsChannel smsChannel = clazz.newInstance();
            if (smsChannel.support(smsChannel)) {
                result = smsChannel.send(mobile, context);
                return result;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
